<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="停车场编号" prop="parkCode">
        <el-input
          v-model="queryParams.parkCode"
          placeholder="请输入停车场编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最终车牌号" prop="enterCarLicenseNumber">
        <el-input
          v-model="queryParams.enterCarLicenseNumber"
          placeholder="请输入最终车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进场时间" prop="enterTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.enterTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择进场时间">
        </el-date-picker>&ensp;-&ensp;
        <el-date-picker clearable size="small"
          v-model="queryParams.endEnterTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:parkEnter:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="parkEnterList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="进场记录表id" align="center" prop="id" v-if="false"/>
      <el-table-column label="停车记录编号" align="center" prop="parkingCode" width="280"/>
      <el-table-column label="停车场编号" align="center" prop="parkCode" />
      <el-table-column label="进场通道" align="center" prop="enterChannelName" />
      <el-table-column label="进场车牌号" align="center" prop="enterCarLicenseNumber" />
      <el-table-column label="进场时间" align="center" prop="enterTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进场放行操作员" align="center" prop="inOperatorName" />
      <el-table-column label="图片详情" align="center" prop="carImage" >
        <template slot-scope="scope">
          <img :src="scope.row.carImage" alt="" width="20%" height="20%" @click="showImg(scope.row.carImage)">
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--  查看图片详情  -->
    <el-dialog :title="imgTitle" :visible.sync="imgOpen" v-if="imgOpen" width="50%" append-to-body>
      <show-imgs :imgs="imgUrl"></show-imgs>
    </el-dialog>

  </div>
</template>

<script>
import { listParkEnter, getParkEnter, delParkEnter, addParkEnter, updateParkEnter, exportParkEnter } from "@/api/system/parkEnter";
import ImageUpload from '@/components/ImageUpload';
import ShowImgs from "@/components/ShowImgs";

export default {
  name: "ParkEnter",
  components: {
    ShowImgs,
    ImageUpload,
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆进场记录表格数据
      parkEnterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      imgOpen: false,
      imgTitle: "",
      imgUrl: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parkCode: undefined,
        enterCarLicenseNumber: undefined,
        enterTime: undefined,
        endEnterTime: undefined,
      },
      pickerOptions: {
        disabledDate(time){
          return time.getTime() > Date.now()
        }
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车辆进场记录列表 */
    getList() {
      this.loading = true;
      listParkEnter(this.queryParams).then(response => {
        this.parkEnterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //显示进场图片
    showImg(imgUrl) {
      this.imgOpen = true;
      this.imgTitle = "进场图片";
      this.imgUrl = imgUrl;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.imgOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        userIds: undefined,
        parkCode: undefined,
        communityId: undefined,
        payMoney: undefined,
        gangtingName: undefined,
        gangtingId: undefined,
        payTime: undefined,
        channelId: undefined,
        plateImage: undefined,
        carImage: undefined,
        userUniqCode: undefined,
        selfInRandomCode: undefined,
        parkingCode: undefined,
        carLicenseNumber: undefined,
        confidence: undefined,
        enterCarLicenseNumber: undefined,
        enterCarCardNumber: undefined,
        enterTime: undefined,
        leaveTime: undefined,
        enterChannelCode: undefined,
        enterChannelName: undefined,
        enterVipType: undefined,
        enterType: undefined,
        enterSpeed: undefined,
        enterCarLicenseColor: undefined,
        enterCarColor: undefined,
        enterCarLogo: undefined,
        enterCarLicenseType: undefined,
        enterCarType: undefined,
        enterRecognitionConfidence: undefined,
        recordType: undefined,
        isCorrect: undefined,
        correctConfidence: undefined,
        correctType: undefined,
        lastCorrectLicenseNumber: undefined,
        lastCorrectName: undefined,
        lastCorrectTime: undefined,
        remark: undefined,
        inOperatorName: undefined,
        inOperateTime: undefined,
        enterCustomVipName: undefined,
        enterImageArray: undefined,
        enterChargeGroupCode: undefined,
        openGateTime: undefined,
        lockKey: undefined,
        thirdUserList: undefined,
        extendInfo: undefined,
        etcStatus: 0,
        type: undefined,
        status: undefined,
        bEntertime: undefined,
        updatetime: undefined,
        createtime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.compareTime(this.queryParams.enterTime,this.queryParams.endEnterTime) == false){
        this.msgError("请选择正确的时间段");
        return false;
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除车辆进场记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delParkEnter(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车辆进场记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportParkEnter(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
